<template>
	<div class="order_list table-theme">
		<head-title title="订单--仓管订单"></head-title>
		<el-card>
			<div class="order_list_head">
				<div class="type-view">
					<div class="client-item" v-for="(item, index) in classifyList" :key="item.index" @click="roleType(index)" :class="[type == index ? 'client-item-active' : '']">
						{{ item.type_name }}
					</div>
				</div>
				<div class="top-menu">
					<div class="menu-left">
					</div>
					<div class="menu-right">
						<refresh-button @refresh="refreshPage"></refresh-button>
						<search-view :option="searchOption" @value="goSearch" @clear="refreshPage" ></search-view>
					</div>
				</div>
			</div>
			<p class="data-number">共{{ total }}条数据</p>
			<el-table :data="orderList" stripe>
				<el-table-column label="序号" align="center" prop="order_id"></el-table-column>
				<el-table-column label="订单号" align="center" prop="order_sn"></el-table-column>
				<el-table-column label="收货人" align="center" prop="address_id.consignee"></el-table-column>
				<el-table-column label="运营人员" v-if="admin_id == 7" align="center" prop="follow_user"></el-table-column>
				<el-table-column label="电话" align="center" prop="address_id.mobile"></el-table-column>
				<el-table-column label="时间" align="center" prop="add_time"></el-table-column>
				<el-table-column label="平台备注" align="center" prop="platform_remark"></el-table-column>
				<el-table-column label="商家物流" align="center" prop="">
					<template slot-scope="scope">
						<el-tooltip content="点击查看地址" placement="bottom" effect="light">
							<p style="cursor: pointer;" @click="addressDetailed(scope.row.direction_detailed)">{{ scope.row.direction }}</p>
						</el-tooltip>
					</template>
				</el-table-column>
				<el-table-column label="地址" align="center">
					<template slot-scope="scope">
						<p>{{ scope.row.address_id.province }}{{ scope.row.address_id.city }}{{ scope.row.address_id.district }}{{ scope.row.address_id.address }}</p>
					</template>
				</el-table-column>
				<el-table-column label="发货时间" align="center" prop="estimate_time"></el-table-column>
				<el-table-column label="厂家物流" align="center" prop="factory_direction"></el-table-column>
				<el-table-column label="状态" align="center">
					<template slot-scope="scope">
						<p style="font-weight: bold;color: #574b90;">{{ scope.row.status_name }}</p>
					</template>
				</el-table-column>
				<el-table-column label="是否入仓" align="center" prop="order_warehouse"></el-table-column>
				<el-table-column label="信息确认" align="center" prop="waite_text"></el-table-column>
				<el-table-column label="导出次数" align="center" prop="excel_count"></el-table-column>
				<el-table-column label="操作" align="center" width="80">
					<template slot-scope="scope">
						<div class="operation">
							<el-button type="primary" size="mini" @click="goOrderDetails(scope.row.order_id)">订单详情</el-button>
							<el-button type="primary" size="mini" @click="onPush(scope.row.order_sn)">推送</el-button>
							<el-button type="primary" size="mini" @click="exportExcel(scope.row.order_id,scope.row.order_sn)">导出</el-button>
						</div>
						
					</template>
				</el-table-column>
			</el-table>
			<div class="pages"><el-pagination background layout="prev, pager, next, jumper" :total="total" @current-change="init" :current-page="page"></el-pagination></div>
		</el-card>
	</div>
</template>

<script>
export default {
	name: 'warehouse_order',
	data() {
		return {
			admin_id: localStorage.getItem('admin_id'), // admin_id  1是总号，2是商家，3是厂家，4财务，5签约，6采购，7仓管 8运营 9设计 10售后
			order_sn: '', // 订单号
			selectContent: '', // 分类搜索平输入框的值
			classSelect: 0, // 判断 是 哪种类型的搜索 1订单编号
			orderList: [], // 订单列表
			total: 0,totalData: 0, 
			type: 0,
			page: 0,
			classifyList: [
				{ type: 0, type_name: '全部' },
				/* { type: 1, type_name: '待确认' }, */
				{ type: 2, type_name: '未支付' },
				{ type: 3, type_name: '已支付' },
				{ type: 4, type_name: '待发货' },
				{ type: 4, type_name: '部分发货' },
				{ type: 5, type_name: '待收货' },
				{ type: 6, type_name: '已完成' },
				{ type: 7, type_name: '已取消' }
			],
			searchOption: [
				{
					value: 0,
					label: '订单号'
				},
				{
					value:1,
					label:'收货人'
				},
				{
					value:2,
					label:"手机号码"
				},
				{
					value:3,
					label:'商品编号'
				}
			],
			order_warehouse:'',
			orderWarehouseList:[
				{
					val:0,
					text:"未入仓"
				},
				{
					val:1,
					text:"部分入仓"
				},
				{
					val:2,
					text:"全部入仓"
				}
			]
		};
	},
	methods: {
		// 初始化列表
		init(e) {
			this.page = e;
			let data = {
				page: e - 1 ? e - 1 : 0,
				limit: 10,
				// order_warehouse:this.order_warehouse
			};
			if (localStorage.getItem('admin_type') != 1) {
				data.store_id = localStorage.getItem('store_id');
				data.goods_store_id = localStorage.getItem('store_id');
			}
			// 1订单编号
			if (this.classSelect == 0) {
				data.order_sn = this.selectContent;
			}else if(this.classSelect == 1){
				data.accept_name = this.selectContent;
			}else if(this.classSelect == 2){
				data.mobile_phone = this.selectContent;
			}else if(this.classSelect == 3){
				data.goods_sn = this.selectContent
			}

			// 0全部 1待确认 2未支付 3已支付 4待发货 5待收货 6已完成 7已取消
			switch (this.type) {
				case 0:
					delete data.order_status;
					delete data.shipping_status;
					delete data.pay_status;
					delete data.waite_status;
					break;
				case 1:
					data.order_status = 0;
					data.shipping_status = 0;
					data.pay_status = 0;
					break;
				case 2:
					data.order_status = '0,1';
					data.shipping_status = '0,1,2';
					data.pay_status = 2;
					data.waite_status = '1,2,3';
					break;
				case 3:
					data.order_status = 0;
					data.shipping_status = 0;
					data.pay_status = 2;
					break;
				case 4:
					data.order_status = 0;
					data.shipping_status = 4;
					data.pay_status = 2;
					break;
				case 5:
					data.order_status = 0;
					data.shipping_status = 1;
					data.pay_status = 2;
					break;
				case 6:
					data.order_status = 1;
					data.shipping_status = 2;
					data.pay_status = 2;
					break;
				case 7:
					delete data.shipping_status;
					delete data.pay_status;
					delete data.waite_status;
					data.order_status = 2;
					break;
			}

			this.$http(this.$ApiList.OrderList, data).then(res => {
				this.orderList = [];
				res.datas.data.forEach(item => {
					if (item.express_move == 1) {
						item.direction = '用户地址';
						item.direction_detailed = item.address_id.city + item.address_id.district + item.address_id.address;
					} else if (item.express_move == 2) {
						item.direction = '商家仓库';
						item.direction_detailed = item.express_address.city + item.express_address.district + item.express_address.address;
					} else if (item.express_move == 3) {
						item.direction = '平台仓库';
						item.direction_detailed = this.platformWarehouse;
					}

					let factory = ['', '客户物流', '客户地址', '平台物流'];
					item.factory_direction = factory[item.factory_move];
					let waite = ['', '待商家确认', '待平台确认', '待工厂确认', '待财务确认', '已确认'];
					if (item.pay_status == 2) {
						item.waite_text = waite[item.waite_status];
					} else {
						item.waite_text = '未付款';
					}

					this.orderList.push(item);
				});

				this.total = res.datas.count;
			});
		},
		goSearch(classSelect, selectContent) {
			this.classSelect = classSelect;
			this.selectContent = selectContent;
			this.init();
		},
		roleType(index) {
			this.selectContent = '';
			this.type = index;
			this.init();
		},
		// 刷新
		refreshPage() {
			this.type = 0;
			this.classSelect = 0;
			this.selectContent = '';
			this.page = 1;
			this.init();
		},
		goOrderDetails(id) {
			this.$router.push({ path: '/order_details', query: { id: id } });
		},
		addressDetailed(direction) {
			this.$alert(direction, '详细地址', {
				confirmButtonText: '确定',
				callback: action => {}
			});
		},
		exportExcel(order_id,order_sn) {
			let url = `${this.$domain}furniture/Adminexcel/GetAllDeliverData?order_id=` + order_id + '&order_sn=' + order_sn;
			window.location.href = url;
		},
		onPush(order_sn){
			this.$http(this.$ApiList.OrderNotice,{order_sn}).then(res=>{
				this.$message.success(res.datas)
			})
		}
	},
	created() {
		this.init();
	}
};
</script>
<style lang="scss" scoped>
.tableLimit tr td .cell {
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2; /*可以显示的行数，超出部分用...表示 */
	-webkit-box-orient: vertical;
}
.order_list_head{
	display: flex;
}
.type-view {
	display: flex;
	flex: 1;
}
.type-view .client-item {
	margin-right: 40px;
	line-height: 40px;
	color: rgba(153, 153, 153, 1);
	cursor: pointer;
}
.client-item-active {
	color: #333333 !important;
	border-bottom: 4px solid #34a1e0;
}
/* 数据筛选 */
.order-export-view {
	margin-right: 10px;
	margin-bottom: 0;
}
.data-filtering-view {
	display: flex;
	align-items: center;
}
.data-filtering-left,
.data-filtering-right {
	display: flex;
}
.data-filtering-right {
	flex: 1;
	flex-direction: row-reverse;
}
.data-filtering-view .select-view {
	margin-left: 10px;
	margin-right: 5px;
}
/* 自定义输入框样式 */
.data-filtering-view .input-with-select .el-input-group__prepend {
	width: 140px;
	background-color: #fff;
}
.data-filtering-view .input-with-select .el-input__inner:nth-child(2) {
	width: 170px;
	padding-right: 15px;
}

/* 数据筛选 -end*/
.operation{
	/deep/ .el-button + .el-button{
		margin-top: 10px;
		margin-left: 0;
	}
}
</style>
